from _datetime import datetime
from pathlib import Path
from typing import Union

from PyQt5.QtCore import QFile

from .logger import Logger
from .pil import CreateThumbnail


def mkdir(file: Path):
    if file.exists() is False:
        file.mkdir(exist_ok=True, parents=True)


def get_now_time(fmt="%Y%m%d"):
    return datetime.now().strftime(fmt)


def getStyleSheetFromFile(file: Union[str, QFile]):
    """ get style sheet from qss file """
    f = QFile(file)
    f.open(QFile.OpenModeFlag.ReadOnly)
    qss = str(f.readAll(), encoding='utf-8')
    f.close()
    return qss
